package com.example.demo.convert;

import com.example.demo.entity.SinaSHStockEntity;
import com.example.demo.entity.SinaUSStockEntity;
import com.example.demo.utils.CommonUtil;
import com.example.demo.utils.StockIndexUtil;

public class Convertor {
    public static SinaSHStockEntity convertArr2SHEntity(String[] arr) {
        SinaSHStockEntity entity = new SinaSHStockEntity();
        entity.setStockName(CommonUtil.defaultIfAbsent(arr[0], ""))
                .setOpenPrice(CommonUtil.defaultIfAbsent(arr[1], ""))
                .setClosePrice(CommonUtil.defaultIfAbsent(arr[2], ""))
                .setCurrPrice(CommonUtil.defaultIfAbsent(arr[3], ""))
                .setHighPrice(CommonUtil.defaultIfAbsent(arr[4], ""))
                .setLowPrice(CommonUtil.defaultIfAbsent(arr[5], ""))
                .setBuyBidding(CommonUtil.defaultIfAbsent(arr[6], ""))
                .setSellBidding(CommonUtil.defaultIfAbsent(arr[7], ""))
                .setVolume(CommonUtil.defaultIfAbsent(arr[8], ""))
                .setTurnover(CommonUtil.defaultIfAbsent(arr[9], ""))
                .setBuyOneVolume(CommonUtil.defaultIfAbsent(arr[10], ""))
                .setBuyOnePrice(CommonUtil.defaultIfAbsent(arr[11], ""))
                .setBuyTwoVolume(CommonUtil.defaultIfAbsent(arr[12], ""))
                .setBuyTwoPrice(CommonUtil.defaultIfAbsent(arr[13], ""))
                .setBuyThreeVolume(CommonUtil.defaultIfAbsent(arr[14], ""))
                .setBuyThreePrice(CommonUtil.defaultIfAbsent(arr[15], ""))
                .setBuyFourVolume(CommonUtil.defaultIfAbsent(arr[16], ""))
                .setBuyFourPrice(CommonUtil.defaultIfAbsent(arr[17], ""))
                .setBuyFiveVolume(CommonUtil.defaultIfAbsent(arr[18], ""))
                .setBuyFivePrice(CommonUtil.defaultIfAbsent(arr[19], ""))
                .setSellOnePrice(CommonUtil.defaultIfAbsent(arr[20], ""))
                .setSellTwoVolume(CommonUtil.defaultIfAbsent(arr[21], ""))
                .setSellTwoPrice(CommonUtil.defaultIfAbsent(arr[22], ""))
                .setSellThreeVolume(CommonUtil.defaultIfAbsent(arr[23], ""))
                .setSellThreePrice(CommonUtil.defaultIfAbsent(arr[24], ""))
                .setSellFourVolume(CommonUtil.defaultIfAbsent(arr[25], ""))
                .setSellFourPrice(CommonUtil.defaultIfAbsent(arr[26], ""))
                .setSellFiveVolume(CommonUtil.defaultIfAbsent(arr[27], ""))
                .setSellFivePrice(CommonUtil.defaultIfAbsent(arr[28], ""))
                .setDate(CommonUtil.defaultIfAbsent(arr[29], ""))
                .setTime(CommonUtil.defaultIfAbsent(arr[30], ""));
        return entity;
    }

    public static SinaUSStockEntity convertArr2USEntity(String[] arr) {
        SinaUSStockEntity entity = new SinaUSStockEntity();

        entity.setStockName(CommonUtil.defaultIfAbsent(arr[0], ""))
                .setCurrPrice(CommonUtil.defaultIfAbsent(arr[1], ""))
                .setIncrPercent(CommonUtil.defaultIfAbsent(arr[2], ""))
                .setTime(CommonUtil.defaultIfAbsent(arr[3], ""))
                .setIncrPrice(CommonUtil.defaultIfAbsent(arr[4], ""))
                .setOpenPrice(CommonUtil.defaultIfAbsent(arr[5], ""))
                .setHighPrice(CommonUtil.defaultIfAbsent(arr[6], ""))
                .setLowPrice(CommonUtil.defaultIfAbsent(arr[7], ""))
                .setHighPrice52(CommonUtil.defaultIfAbsent(arr[8], ""))
                .setLowPrice52(CommonUtil.defaultIfAbsent(arr[9], ""))
                .setVolume(CommonUtil.defaultIfAbsent(arr[10], ""))
                .setAverVolume10(CommonUtil.defaultIfAbsent(arr[11], ""))
                .setTotalMarketVal(CommonUtil.defaultIfAbsent(arr[12], ""))
                .setEarningPerShare(CommonUtil.defaultIfAbsent(arr[13], ""))
                .setPeRatio(CommonUtil.defaultIfAbsent(arr[14], ""))
                .setUnitTurnoverRatio(String.format("%.2f", StockIndexUtil.getUnitTurnoverRatio(entity.getVolume(), entity.getAverVolume10())));

        return entity;
    }
}
